<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="明月">
    <title>简易轮播图</title>
    <style>
        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
        }

        .box {
            width: 520px;
            height: 280px;
            margin: 200px auto;
            position: relative;
        }

        ul {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        li {
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }

        .current {
            display: block;
        }

        section {
            width: 150px;
            height: 20px;
            margin: 0 auto;
            position: relative;
            top: -240px;
            display: flex;
            justify-content: space-around;
        }

        span {
            display: inline-block;
            width: 12px;
            height: 12px;
            background-color: white;
            border-radius: 50%;
            box-shadow: slategray;
        }

        .yuan {
            background-color: red;
        }
    </style>
</head>

<body>
    <div class="box">
        <ul>
            <!-- (li>a[href]>img[src=img/$$.jpg])*5 -->
            <li class="current"><a href=""><img src="img/01.jpg" alt=""></a></li>
            <li><a href=""><img src="img/02.jpg" alt=""></a></li>
            <li><a href=""><img src="img/03.jpg" alt=""></a></li>
            <li><a href=""><img src="img/04.jpg" alt=""></a></li>
            <li><a href=""><img src="img/05.jpg" alt=""></a></li>
        </ul>
    </div>
    <section>
        <span class="yuan"></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </section>
</body>

</html>
<script>
    var lis = document.querySelectorAll('li');
    var spans = document.querySelectorAll('span');
    var index = 0;
    var mytime = setInterval(changImge, 1000);
    function changImge() {
        for (var i = 0; i < lis.length; i++) {
            lis[i].className = '';
            spans[i].className = '';
        }
        index++;
        if (index == 5) {

            index = 0;
        }
        // console.log(index);
        lis[index].className = 'current';
        spans[index].className = 'yuan';
    }


    for (var i = 0; i < spans.length; i++) {
        lis[i].index = i;
        spans[i].index = i;
        spans[i].onmouseover = function () {
            for (var i = 0; i < spans.length; i++) {
                lis[i].className = '';
                spans[i].className = '';
                clearInterval(mytime);
            }
            lis[this.index].className = 'current';
            spans[this.index].className = 'yuan';
        }
        spans[i].onmouseout = function () {
            index = this.index;
            mytime = setInterval(changImge, 1000);
        }
    }

</script>